package com.dys.flex;

import com.dys.mapper.SysUserMapper;
import com.mybatisflex.core.query.QueryWrapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.dys.entity.table.SysUserTableDef.SYS_USER;

/**
 * @Author: 疾风
 * @ClassName: DeleteData
 * @Description: 删除数据测试
 * @CreateDate: 2025/01/14
 * @Version: v1.0.0
 */
@SpringBootTest
public class DeleteData {

    @Autowired
    private SysUserMapper userMapper;

    @Test
    void testDeleteById(){
        // 条件删除
        int row = 0;
        row = userMapper.deleteById(16L);
        System.out.println("受影响行数："+row);
    }

    @Test
    void testDeleteByMap(){
        Map<String, Object> map = new HashMap<>();
        map.put("id",15L);
        int row = 0;
        row = userMapper.deleteByMap(map);
        System.out.println("受影响行数："+row);
    }

    @Test
    void testDeleteByQuery(){
        int row = 0;
        row = userMapper.deleteByQuery(QueryWrapper.create().where(SYS_USER.ID.eq(14)));
        System.out.println("受影响行数："+row);
    }

    @Test
    void testDeleteByCodition(){
        int row = 0;
        row = userMapper.deleteByCondition(SYS_USER.ID.eq(11));
        System.out.println("受影响行数："+row);
    }

    @Test
    void testDeleteByBatch(){
        int row = 0;
        row = userMapper.deleteBatchByIds(List.of(17,18,19));
        System.out.println("受影响行数："+row);
    }

    @Test
    void testFullDelete(){
        // 全表删除
        Assertions.assertThrows(Exception.class, () -> {
            userMapper.deleteByQuery(QueryWrapper.create());
        });
    }
}
